﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Tools.Base;

namespace LogicCenter.Threads
{
    public class MainLogicThread : SingletonTemplate<MainLogicThread>, IMyThread
    {
        private BackgroundWorker _worker = null;

        public void SetMyWorker(BackgroundWorker worker)
        {
            _worker = worker;
        }


        public void ThreadFunc(object sender, EventArgs e)
        {
            while(Program.NeedExitServer == false)
            {

                Thread.Sleep(1);
            }
        }

        public void WaitForExit()
        {
            MyConsole.WriteLineEx(string.Format("{0}正在退出", this.ToString()), ConsoleColor.Green);
            while(_worker != null && _worker.IsBusy)
            {
                Thread.Sleep(1);
            }
            MyConsole.WriteLineEx(string.Format("{0}退出完毕", this.ToString()), ConsoleColor.Green);
        }
    }
}
